<template>
  <div class="book-classify-container">
    <h2>分类页面</h2>
    <div class="classify-title">
      <template v-for="(item, index) in bookName">
        <span
          :class="{active: index === tabIndex }"
          @click="onTabClick(index, item)"
          :key="index"
        >{{item.name}}</span>
      </template>
    </div>
    <div class="classify-content">
      <keep-alive>
        <component :is="componentId"></component>
      </keep-alive>
    </div>
  </div>
</template>

<script>
import HotBook from './components/hot'
import FreeBook from './components/free'
import NewBook from './components/newbook'
import OverBook from './components/overbook'
export default {
  data() {
    return {
      bookName: [
        { name: "热门", com: 'HotBook' },
        { name: "新书", com: 'NewBook' },
        { name: "免费", com: 'FreeBook' },
        { name: "完本", com: 'OverBook' }
      ],
      tabIndex: 0,
      componentId: 'HotBook'
    }
  },
  components: {
    FreeBook,
    HotBook,
    NewBook,
    OverBook
  },
  // activated() {
  //   console.log(1)
  // },
  methods: {
    onTabClick(index, item) {
      this.tabIndex = index;
      this.componentId = item.com
    }
  },
}
</script>

<style lang="scss" scoped>
@import "@/assets/_common.scss";
.book-classify-container {
  width: 100vw;
  .classify-title {
    width: 100%;
    height: 45px;
    display: flex;
    span {
      flex: 1;
      @include flex_center;
      border-bottom: 1px solid #ccc;
    }
    .active {
      /* background: $background_red; */
      color: red;
    }
  }
  .classify-content {
    @include wh;
  }
}
</style>
